import { createRouter, createWebHistory } from 'vue-router'

// 二级路由
export const menu_router = [
  {
    path: '/',
    name: 'home',
    meta: {
      title: '首页'
    },
    component: () => import('../views/home/indexView.vue')
  },
  {
    path: '/list',
    name: 'list',
    meta: {
      title: '列表'
    },
    component: () => import('../views/list/indexView.vue')
  },
  {
    path: '/manage',
    name: 'manage',
    meta: {
      title: '系统管理'
    },
    // 三级路由
    children: [
      {
        path: '/manage/usermanage',
        name: 'usermanage',
        meta: {
          title: '用户管理'
        },
        component: () => import('../views/usermanage/indexView.vue')
      },
      {
        path: '/manage/rolemanage',
        name: 'rolemanage',
        meta: {
          title: '角色管理'
        },
        component: () => import('../views/rolemanage/indexView.vue')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: () => import('../views/layout/indexView.vue'),
      children: menu_router
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/login/indexView.vue')
    },
    {
      path: '/403',
      name: '403',
      component: () => import('../views/403/indexView.vue')
    },
    // {
    //   path: '/:pathMatch(.*)*',
    //   name: '404',
    //   component: ()=>import('../views/404/indexView.vue')
    // },
    {
      path: '/404',
      name: '404',
      component: () => import('../views/404/indexView.vue')
    },
    {
      path: '/:pathMatch(.*)*',
      redirect: '/404' // 重定向
    }
  ]
})

export default router
